home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / tagline.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1997-06-09  |  4.7 KB  |  115 lines

  1. /*                        Tagline.rexx
  2.                          v1.4 05-Dec-96
  3.  
  4.  -Adds a random tagline to all messages in the outgoing folder.
  5.  -Tagfile should contain taglines separated by one separator line.  You
  6.   can define the separator yourself.
  7.  -No tagline is used again until they are all used once. (During one execution
  8.   of the script, naturally)
  9.  -It's possible not to use taglines with certain adresses.  Just list them
  10.   in variable no_tags
  11.  -Variable permanent contains text which is added to every message.  It may
  12.   contain linefeeds, for example:
  13.           permanent='Yours truly,'NL'   Kai Nikulainen'
  14.  -hedrickd@bikerider.com added pretag. It's added after permanent but before tag
  15.   The difference between permanent and pretag is: permanent is added to every
  16.   message, pretag only to in messages which taglines are allowed.
  17.  
  18.    As always comments and bug reports are welcomed at knikulai@utu.fi
  19. */
  20. options results
  21. NL='0a'x            /* Newline */
  22.  
  23. /* 
  24. ** Change these values to your liking
  25. */
  26.   tagfiles=11            /* Number of tagfiles */
  27.   tagfile.1='packed:txt/taglines_1'  /* Their names */
  28.   tagfile.2='packed:txt/taglines_2'  
  29.   tagfile.3='packed:txt/taglines_3'  
  30.   tagfile.4='packed:txt/taglines_4'  
  31.   tagfile.5='packed:txt/taglines_5'  
  32.   tagfile.6='packed:txt/taglines_6'  
  33.   tagfile.7='packed:txt/taglines_7'  
  34.   tagfile.8='packed:txt/taglines_8'  
  35.   tagfile.9='packed:txt/taglines_9'  
  36.   tagfile.10='packed:txt/taglines_10'  
  37.   tagfile.11='packed:txt/taglines_11'  
  38.  
  39. separator='$'
  40. permanent='' 
  41.   no_tags='yam@dsdelft.nl ' /* list of addresses which will not be able to enjoy your tags */
  42.    pretag=NL/* Your Custom line to go before your tagline */
  43.  
  44.  
  45.  
  46. call random(,,time(s))      /* Let's make this really random */
  47.  
  48. /* let's first read all taglines */
  49. tc=1            /* How many tags are there? */
  50. tags.1=''       /* Set the first to empty */
  51. tagnum=random(1,tagfiles)              /* Select a tagfile */
  52. if open(in,tagfile.tagnum,'R') then do /* A tagfile was found */
  53.   do until eof(in)              /* Read everything in it */
  54.       rivi=readln(in)             /* Read one line */
  55.       if rivi=separator then do   /* If the line was separator line */
  56.             tc=tc+1               /* Next nonblank line will begin a new tag.. */
  57.             tags.tc=''            /* which will be empty first */
  58.          end
  59.       else                                /* The line was not a separator */
  60.          tags.tc=tags.tc || rivi || NL    /* Add it to the current tagline */
  61.       end /* do until eof*/
  62.   call close(1)                 /* Close tagfile */
  63.   end
  64. else do
  65.   address 'YAM' 'Request "Could not open ' ||tagfile.tagnum||'!" "OK"'
  66.   exit
  67.   end
  68.  
  69. if tags.tc='' then tc=tc-1 /* Let's just be sure there are no blanks... */
  70.  
  71. maxtag=tc               /* maxtag tells how many taglines are unused */
  72.  
  73. address 'YAM'           /* Let's tell YAM what to do.. */
  74.  
  75. 'SetFolder 1'
  76. 'GetFolderInfo Max'     /* How many messages are there? */
  77. n=result                /* Remember it! */
  78. do m=0 to n-1           /* Do for each message in folder: */
  79.    'SetMail' m                          /* Select it */
  80.    'GetMailInfo File'                   /* Get name of the mailfile */
  81.    call open(out,result,'A')            /* Open it for appending */
  82.    if permanent~='' then                /* If there is a line for every mail,*/
  83.      writeln(out,permanent)             /* then write it */
  84.    'GetMailInfo To'                     /* Get receiver */
  85.    if ok_to_add_tag(result) then do     /* Is the address in the forbidden list? */
  86.      i=rnd(maxtag)                      /* Get a random number 1..maxtag */
  87.      if pretag~='' then
  88.         writeln(out,pretag)             /* Add customized line before Tagline */
  89.      writeln(out,tags.i)                /* Write the tagline */
  90.      temp=tags.maxtag                   /* Swap the last unused.. */
  91.      tags.maxtag=tags.i                 /* ...and just used tag */
  92.      tags.i=temp                        /* Last used tag is now last */
  93.      maxtag=maxtag-1                    /* Decrease counter ==> it wont be used again*/
  94.      if maxtag=0 then maxtag=tc         /* All tags were used, so reset counter */
  95.    end /* if ok_to_add_tag(result)*/
  96.    call close(out)                    /* Close message file */
  97. end /* do m= */
  98.  
  99. exit
  100.  
  101. ok_to_add_tag:
  102. /* Check if the address is listed in no_tags list */
  103.         parse arg email
  104.         email=translate(email,' ','<>()",',' ') /* Remove unwanted chars */ 
  105.     email=word(email,words(email))
  106.         return pos(email,no_tags)=0         /* Was it in the list? */
  107.  
  108. rnd:
  109. /* random can't handle big numbers... This will create a big number and get
  110. ** modulo n+1.  This needs editing, if you have more than 30999 taglines... :-)
  111. */
  112.   parse arg n
  113.   r=1+(1000*random(1,30)+random(1,999))//n
  114. return r
  115.